package com.zys.http.extension.completion.properties.psi;


import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFileFactory;
import com.zys.http.extension.completion.properties.language.HttpPropertiesFileType;

/**
 * @author zys
 * @since 2025-08-19
 */
public class HttpPropertiesElementFactory {
    public static HttpPropertiesProperty createProperty(Project project, String name) {
        final HttpPropertiesFile file = createFile(project, name);
        return (HttpPropertiesProperty) file.getFirstChild();
    }

    public static HttpPropertiesFile createFile(Project project, String text) {
        String name = "dummy.HttpProperties";
        return (HttpPropertiesFile) PsiFileFactory.getInstance(project).createFileFromText(name, HttpPropertiesFileType.INSTANCE, text);
    }

    public static HttpPropertiesProperty createProperty(Project project, String name, String value) {
        final HttpPropertiesFile file = createFile(project, name + " = " + value);
        return (HttpPropertiesProperty) file.getFirstChild();
    }

    public static PsiElement createCRLF(Project project) {
        final HttpPropertiesFile file = createFile(project, "\n");
        return file.getFirstChild();
    }
}